from fastapi import FastAPI,Form
from starlette.requests import Request
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates

app = FastAPI()
templates = Jinja2Templates(directory="templates")
app.mount('/static',StaticFiles(directory='static'),name='static')


@app.post("/user/")
async def userhome(request:     Request,
                   username:    str=Form(...),
                   password:    str=Form(...),
                   ):
    nickname = username[0] + '工'

    # TODO  确定用户的身份
    # TODO  通过身份确定可操作的功能
    return templates.TemplateResponse(
        'index.html',
        {
            'request':request,
            'username': nickname,
            'userid': "1",
        }
                                      )

@app.get("/")
async def login(request:Request):
    # TODO  密码验证
    return templates.TemplateResponse('signin.html',{'request':request})


@app.get("/tools/{userid}")
async def tool(request:Request,userid:str):
    return templates.TemplateResponse('number.html,',{'request':request})

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app,host="127.0.0.1",port=8080)

